home *** CD-ROM | disk | FTP | other *** search
-
-
-
- ffffcccclllloooosssseeee((((3333SSSS)))) ffffcccclllloooosssseeee((((3333SSSS))))
-
-
-
- NNNNAAAAMMMMEEEE
- _ffff_cccc_llll_oooo_ssss_eeee, _ffff_ffff_llll_uuuu_ssss_hhhh - close or flush a stream
-
- SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
- _####_iiii_nnnn_cccc_llll_uuuu_dddd_eeee _<<<<_ssss_tttt_dddd_iiii_oooo_...._hhhh_>>>>
-
- _iiii_nnnn_tttt _ffff_cccc_llll_oooo_ssss_eeee _((((_FFFF_IIII_LLLL_EEEE _****_s_t_r_e_a_m_))))_;;;;
-
- _iiii_nnnn_tttt _ffff_ffff_llll_uuuu_ssss_hhhh _((((_FFFF_IIII_LLLL_EEEE _****_s_t_r_e_a_m_))))_;;;;
-
- DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
- _ffff_cccc_llll_oooo_ssss_eeee causes any buffered data waiting to be written for the named
- _s_t_r_e_a_m [see _iiii_nnnn_tttt_rrrr_oooo(3)] to be written out, and the _s_t_r_e_a_m to be closed. If
- the underlying file pointer is not already at end of file, and the file
- is one capable of seeking, the file pointer is adjusted so that the next
- operation on the open file pointer deals with the byte after the last one
- read from or written to the file being closed.
-
- If _s_t_r_e_a_m points to an output stream or an update stream on which the
- most recent operation was not input, _ffff_ffff_llll_uuuu_ssss_hhhh causes any buffered data
- waiting to be written for the named _s_t_r_e_a_m to be written to that file.
- Any unread data buffered in _s_t_r_e_a_m is discarded. The _s_t_r_e_a_m remains
- open.
-
- When calling _ffff_ffff_llll_uuuu_ssss_hhhh, if _s_t_r_e_a_m is a null pointer, all files open for
- writing only and all files open for update whose last operation was a
- write are flushed.
-
- _ffff_ffff_llll_uuuu_ssss_hhhh(_NNNN_UUUU_LLLL_LLLL) is performed automatically on calling _eeee_xxxx_iiii_tttt.
-
- NNNNOOOOTTTTEEEESSSS
- If two _s_t_r_e_a_m_s point to the same underlying file descriptor, the
- semantics associated with their use is complex. They are described in
- detail in the _P_O_S_I_X_9_0 _1_0_0_3._1 _s_e_c_t_i_o_n _8._2._3. The most common way for an
- unsuspecting application writer to wander into this situation is via
- _ffff_oooo_rrrr_kkkk(2). _ffff_oooo_rrrr_kkkk of course replicates the process, including any stdio
- buffers, while both the parent's and child's underlying file descriptor
- share a common file offset pointer. This means that actions performed in
- one process may affect the other. Consider the following:
-
- Parent:
- fp = fopen("foo", "r");
- fread(buf, 100, 1, fp);
- fork();
- wait(NULL);
- fread(buf, BUFSIZ+1, 1, fp);
- Child:
- fclose(fp);
- exit(0);
-
- The parent reads the first 100 bytes which really reads _BBBB_UUUU_FFFF_SSSS_IIII_ZZZZ bytes into
- an internal _s_t_r_e_a_m buffer. The underlying file descriptor has its file
-
-
-
- PPPPaaaaggggeeee 1111
-
-
-
-
-
-
- ffffcccclllloooosssseeee((((3333SSSS)))) ffffcccclllloooosssseeee((((3333SSSS))))
-
-
-
- offset set to _BBBB_UUUU_FFFF_SSSS_IIII_ZZZZ. After the _ffff_oooo_rrrr_kkkk, the parent waits for the child.
- The child calls _ffff_cccc_llll_oooo_ssss_eeee which causes the underlying file descriptor to be
- synchronized with _s_t_r_e_a_m. In this case that means that an _llll_ssss_eeee_eeee_kkkk on the
- underlying file descriptor will be performed to set the file offset back
- to 100. Since the file descriptor offset pointer is shared between
- parent and child, the parent's file descriptor now points at offset 100.
- When the parent continues reading and finishes the first buffer, a second
- buffer will be read. The parent is assuming that the file offset is
- still at _BBBB_UUUU_FFFF_SSSS_IIII_ZZZZ but the child's actions have changed it to 100. The
- parent will get the incorrect data. The solution to this to either not
- have the child call _ffff_cccc_llll_oooo_ssss_eeee or to synchronize the file descriptor with
- _s_t_r_e_a_m before calling _ffff_oooo_rrrr_kkkk. Synchronization is done by calling
- _ffff_ffff_llll_uuuu_ssss_hhhh(_f_p). Note that calling _ffff_ffff_llll_uuuu_ssss_hhhh(_NNNN_UUUU_LLLL_LLLL) will not suffice since it
- doesn't effect read only streams.
-
- SSSSEEEEEEEE AAAALLLLSSSSOOOO
- _cccc_llll_oooo_ssss_eeee(2), _eeee_xxxx_iiii_tttt(2), _iiii_nnnn_tttt_rrrr_oooo(3), _ffff_oooo_pppp_eeee_nnnn(3S), _ssss_eeee_tttt_bbbb_uuuu_ffff(3S), _ssss_tttt_dddd_iiii_oooo(3S)
-
- DDDDIIIIAAAAGGGGNNNNOOOOSSSSTTTTIIIICCCCSSSS
- On successful completion these functions return a value of zero.
- Otherwise _EEEE_OOOO_FFFF is returned. For _ffff_ffff_llll_uuuu_ssss_hhhh(_NNNN_UUUU_LLLL_LLLL), an error is returned if any
- files encounter an error. For _ffff_cccc_llll_oooo_ssss_eeee, _EEEE_OOOO_FFFF is returned if _s_t_r_e_a_m is _NNNN_UUUU_LLLL_LLLL,
- or _s_t_r_e_a_m is not active, or there was an error when flushing buffered
- writes, or there was an error closing the underlying file descriptor.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- PPPPaaaaggggeeee 2222
-
-
-
-